import { ref, computed, reactive } from 'vue'
import { defineStore } from 'pinia'

export const useMetaStore = defineStore('meta', () => {
	const metas = ref([])
	function setMeta (meta) {
		metas.value = meta
	}
	function getMeta () {
		return metas.value
	}
	return { metas, setMeta, getMeta }
})

export const useLoadingStore = defineStore('loading', () => {
	const loading = ref(0)
	function openLoading() {
		loading.value++
	}
	function closeLoading() {
		loading.value--
	}
	return { loading, openLoading, closeLoading }
})

export const userTokenStore = defineStore('token', () => {
	const token = ref(null)
	function setToken (value) {
		token.value = value
	}
	function getToken () {
		return token.value
	}
	return { token, setToken, getToken }
}, {
		persist: {
			storage: sessionStorage
		}
	}
)
export const userInfoStore = defineStore('userInfo', () => {
	const userInfo = reactive({})
	function setUserInfo (value) {
		for (const key in value) {
			userInfo[key] = value[key]
		}
	}
	function getUserInfo () {
		return userInfo
	}
	return { userInfo, setUserInfo, getUserInfo }
}, {
		persist: {
			storage: sessionStorage
		}
	}
)
export const useAiSessionStore = defineStore('aiSession', () => {
	const sessionId = ref(null)
	function setSessionId (value) {
		sessionId.value = value
	}
	function getSessionId () {
		return sessionId.value
	}
	return { sessionId, setSessionId, getSessionId }
}, {
	persist: {
		storage: sessionStorage
	}
})